/*******************************************************************************
Paper: Does the Production Approach to Markup Estimation Match a Stylized Fact?
Description: Produces Table 1 and Figure 1a and 1b
Author: Tove Forsbacka
Last Updated: 15 February 2026
*******************************************************************************/

* Setup and environment control 
clear
set more off
capture log close 
version 18.5
*ssc install ftools
*ssc install reghdfe
*ssc install did_multiplegt_dyn

* Define path and load the data
*cd "PROJECT_PATH"
use "markups.dta"

* Table 1

* Define control variables and fixed effects
local controls "lpopulation_density lincome market_chain" 
local fe "i.Länskod i.year"

* Lable variables
label variable markup_mean "Markup
label variable market_chain "Chain
label variable lincome "Income (log)
label variable lpopulation_density "Pop. dens. (log)

* Table 1, Panel A: Monopoly/duopoly/triopoly
reg markup_mean monopoly duopoly triopoly `controls' `fe' if market_grocery == 1, ///
cluster(Kommunkod) 
outreg2 using table1_panelA.tex, replace label keep(monopoly duopoly triopoly) ///
 ctitle(grocery stores)

reg markup_mean monopoly duopoly triopoly `controls' `fe' if market_driving == 1, ///
 cluster(Kommunkod) 
outreg2 using table1_panelA.tex, append label  keep(monopoly duopoly triopoly) ///
 ctitle(driving schools)

reg markup_mean monopoly duopoly triopoly `controls' `fe' if market_taxi == 1, ///
 cluster(Kommunkod) 
outreg2 using table1_panelA.tex, append label  keep(monopoly duopoly triopoly) ///
 ctitle(taxis)

reg markup_mean monopoly duopoly triopoly `controls' `fe'  if market_hairdresser == 1, ///
 cluster(Kommunkod) 
outreg2 using table1_panelA.tex, append label  keep(monopoly duopoly triopoly) ///
 ctitle(hairdressers)

* Table 1, Panel B: HHI
reg markup_mean hhi `controls' `fe' if market_grocery == 1, cluster(Kommunkod) 
outreg2 using table1_panelB.tex, replace label keep(hhi) ctitle(grocery stores)

reg markup_mean hhi `controls' `fe' if market_driving == 1, cluster(Kommunkod) 
outreg2 using table1_panelB.tex, append label keep(hhi) ctitle(driving schools)

reg markup_mean hhi `controls' `fe' if market_taxi == 1, cluster(Kommunkod) 
outreg2 using table1_panelB.tex, append label keep(hhi) ctitle(taxis)

reg markup_mean hhi `controls' `fe'  if market_hairdresser == 1, cluster(Kommunkod) 
outreg2 using table1_panelB.tex, append label keep(hhi) ctitle(hairdressers)


* Figures

* Keep only the grocery sector
keep if market_grocery==1

* Define control variables
local controls "lpopulation_density lincome" 

* Set panel
xtset localmarket year

* Create indicators for entry and exits
bysort localmarket: gen entry = 1 if duopoly == 1 & monopoly[_n-1] == 1
replace entry = 0 if entry ==.

bysort localmarket: gen exit = 1 if monopoly == 1 & duopoly[_n-1] == 1
replace exit = 0 if exit ==.

* Summary statistics
xtsum entry exit
tab entry
tab exit

* Figure 1a: Entry
did_multiplegt_dyn markup_mean Kommunkod year entry, cluster(Kommunkod) ///
 controls(`controls') effects(4) placebo(2)  graphoptions(ylabel(-0.05(0.025)0.05, ///
 angle(0) grid glcolor(dimgray)) xlabel(-2(1)4) yline(0.05, lstyle(grid) ///
 lcolor(dimgray)) scheme(s2mono) graphregion(color(white)) bgcolor(white) ///
 legend(off) ytitle() xtitle(Time to treatment))
graph export 1a_entry.pdf, replace

* Figure 1b: Exit
did_multiplegt_dyn markup_mean Kommunkod year exit, cluster(Kommunkod) ///
 controls(`controls') effects(4) placebo(2)   graphoptions(ylabel(-0.05(0.025)0.05, ///
 angle(0) grid glcolor(dimgray)) xlabel(-2(1)4) yline(-0.05, lstyle(grid) ///
 lcolor(dimgray)) scheme(s2mono) graphregion(color(white)) bgcolor(white)  ///
 legend(off) ytitle() xtitle(Time to treatment))
graph export 1b_exit.pdf, replace
